# -*- coding: utf-8 -*-




class DBObject:

	def __init__(self):
		self._things = {} #inheirited
		self._needToUpdate = []

	def __getattr__(self, name):

		try:
			item = self._things[name]
		except KeyError:
			raise AttributeError, name

		if not item:
			item = self._getItem(name)

		return item

	def _getItem(self, name):
		raise AttributeError, name

	def updateDB(self, name):
		raise Exception, "There is no updateDB function for this type"

	def insert(self):
		raise Exception, "There is no updateDB function for this type"


	def __setattr__(self, name, value):

		# "base case" to prevent recursion
		if name == '_things':
			self.__dict__[name] = value
			return

		if name in self._things:
			self._things[name] = value
			self.updateDB(name)
		else:
			self.__dict__[name] = value		#if not in things then put in our dict

		#Need to call something to update database???